#ifndef MYFUNCX_H
#define MYFUNCX_H

#include <QtScript>
#include "funcx.h"
#include <algorithm>

class CMyFuncX1: public CFuncX
{
public:
	virtual ~CMyFuncX1(){}
	virtual double operator()(const vector<double> &x)
	{
		double res = 0.0;
		if (x.size() == 3)
			res = x[0]*x[0]+x[1]*x[1]+x[2]*x[2]+1.0;

		return res;
	}
};

class CJSFuncX: public CFuncX
{
	QString m_str;
	QScriptEngine m_engine;
	QScriptValue m_f;

public:
	CJSFuncX(const QString & str): m_str(str)
	{
		m_engine.evaluate(m_str);
		m_f = m_engine.globalObject().property("f");
	}
	virtual ~CJSFuncX(){}
	virtual double operator () (const vector<double> &x)
	{
		double res = 0.0;
		QScriptValueList args;
		args << qScriptValueFromSequence(&m_engine, x);
		res = m_f.call(QScriptValue(), args).toNumber();

		return res;
	}
};

#endif // MYFUNCX_H
